package com.pk.platform.business.common.dao.impl;

import java.util.ArrayList;
import java.util.List;

import com.pk.platform.business.common.dao.IContactDao;
import com.pk.platform.business.common.vo.ContactVO;
import com.pk.platform.business.core.dao.impl.GenericDaoImpl;
import com.pk.platform.util.StringConverter;
import com.pk.platform.util.page.ListPage;
import com.pk.platform.util.page.Pager;

public class ContactDaoImpl extends GenericDaoImpl implements IContactDao {

	public ListPage queryContact(ContactVO ctvo, Pager pager) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from contact ct where 1 = 1");
		List<Object> param = new ArrayList<Object>();
		if(StringConverter.isNotNull(ctvo.getCotact().getName()))
		{
			sql.append(" and ct.name like ?");
			param.add("%" + ctvo.getCotact().getName() + "%");
		}
		if(StringConverter.isNotNull(ctvo.getCotact().getEmail()))
		{
			sql.append(" and ct.email like ?");
			param.add("%" + ctvo.getCotact().getEmail() + "%");
		}
		if(StringConverter.isNotNull(ctvo.getCotact().getAddress()))
		{
			sql.append(" and ct.address like ?");
			param.add("%" + ctvo.getCotact().getAddress() + "%");
		}
		if(StringConverter.isNotNull(ctvo.getCotact().getPhone()))
		{
			sql.append(" and ct.phone like ?");
			param.add("%" + ctvo.getCotact().getPhone() + "%");
		}
		if(StringConverter.isNotNull(ctvo.getKindergartenId()))
		{
			sql.append(" and ct.kgid = ?");
			param.add(ctvo.getKindergartenId());
		}else
			sql.append(" and ct.kgid is null ");
		sql.append(" order by ct.name ");
		return this.getListPage(sql.toString(), param.toArray(), pager);
	}


	
}
